package com.konsung.ksdc.manager.machine;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.konsung.ksdc.R;
import com.konsung.ksdc.common.utils.ImageUtils;

import java.io.File;

import butterknife.Bind;
import butterknife.ButterKnife;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * 社区聊天图片的全屏显示及缩放
 * Created by Administrator on 2016/3/29 0029.
 */
public class PicViewActivity extends Activity {
    public static final String PIC_FILE = "picFile";

    @Bind(R.id.iv_pic)
    PhotoView ivPic;

    private Bitmap bitmap;
    private PhotoViewAttacher photoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_pic_view);
        ButterKnife.bind(this);
        final File picFile = (File) getIntent().getSerializableExtra("picFile");
        ImageUtils imageUtils = new ImageUtils();
        bitmap = imageUtils.ratio(picFile.getPath());
        ivPic.setImageBitmap(bitmap);
        photoView = new PhotoViewAttacher(ivPic);
        photoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                finish();
            }
        });
        ivPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        super.onDestroy();
    }
}
